﻿
// 2019/4/22: 首个记录
// 2019/9/19: 增加USoundSensorProperty默认构造函数
// 2019/10/11: 修改pragma once和include
// 2020/1/14: 接口完整性
// 2020/11/12: 支持Spadas7
// 2022/11/2: 支持Spadas8.4
// 2023/10/11: 补充部分英文注释
// 2024/7/3: 基于新样本框架
// 2025/4/7: 实现插值和fromSample

#ifndef USOUND_SAMPLE_V1_H
#define USOUND_SAMPLE_V1_H

#include "spadas.h"

namespace usound_sample_v1
{
	using namespace spadas;

	struct USoundSensorProperty
	{
		Double originX; // [m] X-coordinate of the n-th sensor's position / 传感器原点X坐标
		Double originY; // [m] Y-coordinate of the n-th sensor's position / 传感器原点Y坐标
		Double orientation; // [°] Central heading angle of the n-th sensor / 传感器中心轴朝向
		Double angleRangeAlpha; // [°] α angle range (generally around 100°, with sensor's origin as the center of the circle) / α角范围（一般在100°左右，以OriginX/Y为圆心）
		Double angleRangeBeta; // [°] β angle range (generally ranges 0~30°) / β角范围（一般在0~30°）
		Double distanceRangeAlpha; // [m] Detect range corresponding to α angle (shorter) / α角对应的探测距离（较短）
		Double distanceRangeBeta; // [m] Detect range corresponding to β angle (longer) / β角对应的探测距离（较长）

		USoundSensorProperty()
		{
			originX = 0;
			originY = 0;
			orientation = 0;
			angleRangeAlpha = 100;
			angleRangeBeta = 15;
			distanceRangeAlpha = 0.5;
			distanceRangeBeta = 2.5;
		}
	};

	struct USoundSensorData
	{
		Int id; // Sensor ID, starting from 1 / 传感器ID，从1开始
		USoundSensorProperty properties; // Sensor properties / 超声波传感器属性
		OptionalDouble distance; // [m] Detected barrier's distance, invalid indicates no barrier / 障碍物的距离，无障碍物则为空
	};

	struct USoundSampleData
	{
		Array<USoundSensorData> dataList; // Data of each sensor / 各个超声波传感器的数据

		USoundSampleData()
		{}
	};

	class USoundSample : public Object<class USoundSampleVars>
	{
	public:
		SPADAS_TYPE("usound_sample_v1.USoundSample")

		USoundSample();
		FullTimestamp& timestamp();
		USoundSampleData *operator ->();

		static String getProtocolName();
		SessionGeneralSample toGeneralSample();

		static Array<String> getProtocolNames();
		Bool fromGeneralSample(String protocol, SessionGeneralSample generalSample);
	};
}

#endif